//
//  RansomNewCell.m
//  LuCaiZhu
//
//  Created by 邓龙 on 2019/4/4.
//

#import "RansomNewCell.h"

@interface RansomNewCell()

@property (weak, nonatomic) IBOutlet UILabel *orderId; //订单号
@property (weak, nonatomic) IBOutlet UILabel *openDate; //订单对应开放日
@property (weak, nonatomic) IBOutlet UILabel *shareNum; //订单存续份额
@property (weak, nonatomic) IBOutlet UILabel *ransomShareNum; //赎回份额拆分
@property (weak, nonatomic) IBOutlet UILabel *shenyuShare; //剩余份额
@property (weak, nonatomic) IBOutlet UILabel *buyFee; //认购净值
@property (weak, nonatomic) IBOutlet UILabel *randomFee; //赎回净值
@property (weak, nonatomic) IBOutlet UILabel *shouyiMoney; //收益
@property (weak, nonatomic) IBOutlet UILabel *shouyilv; //收益率
@property (weak, nonatomic) IBOutlet UILabel *totalFee; //目前存续份额合计
@property (weak, nonatomic) IBOutlet UILabel *totalRandomFee; //赎回后存续份额合计
@property (weak, nonatomic) IBOutlet UILabel *totalRandomLab;

@end

@implementation RansomNewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setHiddenAction:(BOOL)hidden {
    if (hidden) {
        _totalRandomFee.hidden = YES;
        _totalRandomLab.hidden= YES;
    }
    else {
        _totalRandomFee.hidden = NO;
        _totalRandomLab.hidden= NO;
    }
}

//赎回订单明细
- (void)setDetailInfoData:(RansomOrderDetInfoModel *)model {
    _orderId.text = [NSString stringWithFormat:@"订单号：%@", model.OrderCode];
    _openDate.text = [NSString stringWithFormat:@"%@ %@", model.OrderOpenDate, model.BookingType];
    _shareNum.text = model.OrderCunXunShare;
    _ransomShareNum.text = model.RedeemShareLine;
    _shenyuShare.text = model.OrderLeftShare;
    _buyFee.text = model.BuyNet;
    _randomFee.text = model.RedeemNet;
    _shouyiMoney.text = model.Profit;
    _shouyilv.text = model.ProfitRate;
}

- (void)setBottomData:(NSDictionary *)dic and:(BOOL)isDetail {
    if (isDetail) {
        _totalFee.text = dic[@"TotalShare"];
        _totalRandomFee.text = dic[@"SurplusShare"];
    }
    else {
        _totalFee.text = [self positiveFormat: [self removeFloatAllZero: dic[@"TotalShare"]]];
        _totalRandomFee.text = [self positiveFormat: [self removeFloatAllZero: dic[@"SurplusShare"]]];
    }
}

- (void)setDataJumpAction:(NSDictionary *)dic {
    _orderId.text = [NSString stringWithFormat:@"订单号：%@", dic[@"BookingNo"]];
    _openDate.text = [NSString stringWithFormat:@"%@ %@", dic[@"OpenDay"], dic[@"BookingType"]];
    _shareNum.text = dic[@"SurvivingShare"];
    _ransomShareNum.text = dic[@"RedeemShare"];
    _shenyuShare.text = dic[@"RemainingShare"];
}

- (NSString *)positiveFormat:(NSString *)text{
    if(!text || [text floatValue] == 0){
        return @"0";
    }
    if (text.floatValue < 1000) {
        return  [self removeFloatAllZero: [NSString stringWithFormat:@"%.2f",text.floatValue]];
    };
    
    if ([text containsString:@".0"]) {
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@",###.00;"];
        return [numberFormatter stringFromNumber:[NSNumber numberWithDouble:[text doubleValue]]];
    }
    
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@",###;"];
    return [numberFormatter stringFromNumber:[NSNumber numberWithDouble:[text doubleValue]]];
}

-(NSString*)removeFloatAllZero:(NSString*)string
{
    NSString * testNumber = string;
    NSString * outNumber = [NSString stringWithFormat:@"%@",@(testNumber.floatValue)];
    return outNumber;
}

@end
